package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllTopicPolls", query = "select myTopicPoll from TopicPoll myTopicPoll"),
		@NamedQuery(name = "findTopicPollByDisplayName", query = "select myTopicPoll from TopicPoll myTopicPoll where myTopicPoll.displayName = ?1"),
		@NamedQuery(name = "findTopicPollByDisplayNameContaining", query = "select myTopicPoll from TopicPoll myTopicPoll where myTopicPoll.displayName like ?1"),
		@NamedQuery(name = "findTopicPollById", query = "select myTopicPoll from TopicPoll myTopicPoll where myTopicPoll.id = ?1"),
		@NamedQuery(name = "findTopicPollByPrimaryKey", query = "select myTopicPoll from TopicPoll myTopicPoll where myTopicPoll.id = ?1") })
@Table(catalog = "sow", name = "topic_poll")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "TopicPoll")
@XmlRootElement(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain")
public class TopicPoll implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "DISPLAY_NAME", length = 200, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String displayName;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "TOPIC_ID", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	Topic topic;
	/**
	 */
	@OneToMany(mappedBy = "topicPoll", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.TopicPollUser> topicPollUsers;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	/**
	 */
	public String getDisplayName() {
		return this.displayName;
	}

	/**
	 */
	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	/**
	 */
	@JsonIgnore
	public Topic getTopic() {
		return topic;
	}

	/**
	 */
	public void setTopicPollUsers(Set<TopicPollUser> topicPollUsers) {
		this.topicPollUsers = topicPollUsers;
	}

	/**
	 */
	@JsonIgnore
	public Set<TopicPollUser> getTopicPollUsers() {
		if (topicPollUsers == null) {
			topicPollUsers = new java.util.LinkedHashSet<edu.hcmus.sow.domain.TopicPollUser>();
		}
		return topicPollUsers;
	}

	/**
	 */
	public TopicPoll() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(TopicPoll that) {
		setId(that.getId());
		setDisplayName(that.getDisplayName());
		setTopic(that.getTopic());
		setTopicPollUsers(new java.util.LinkedHashSet<edu.hcmus.sow.domain.TopicPollUser>(that.getTopicPollUsers()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("displayName=[").append(displayName).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof TopicPoll))
			return false;
		TopicPoll equalCheck = (TopicPoll) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
